package org.example.ruangong.mapper;

import org.apache.ibatis.annotations.*;
import org.example.ruangong.model.Entry;

import java.util.List;

@Mapper
public interface EntryMapper {

//    @Insert("INSERT INTO entry (eid, title, keys, article, users) VALUES (#{eid}, #{title}, #{keys}, #{article}, #{users})")
//    void insertEntry(Entry entry);
    void insertEntry(Entry entry);
//    @Update("UPDATE entry SET title = #{title}, article = #{article} WHERE eid = #{eid}")
    void updateEntry(Entry entry);

//    @Select("SELECT * FROM entry WHERE eid = #{eid}")
    Entry selectEntryById(Integer eid);

//    @Select("SELECT * FROM entry WHERE keys LIKE #{keyPattern}")
    List<Entry> selectEntriesByKey(String keyPattern);

//    @Select("SELECT e.* FROM entry e JOIN entry_users eu ON e.eid = eu.eid WHERE eu.uid = #{uid}")
    List<Entry> selectEntriesByUid(Integer uid);

//    @Update("UPDATE entry SET users = CONCAT(users, ' ', #{userName}) WHERE eid = #{eid}")
    void addUserToEntry(@Param("eid") Integer eid, @Param("userName") String userName);
}